/**
 * Created by wenpeng on 2017/1/11.
 */
$(function () {
    var currentSta = 0,
        currentPage = 1,
        src;
    $('.choose > div').on('click', function () {
        var num = $($(this).find('img')).data('img');
        $('.choose .one').removeClass('currentState')
        $(this).find('.one').addClass('currentState')
        src = num === 2 ?'img/choose-dx.png':'img/choose-gx.png';
        $('.choose img').each(function (index) {
            if(index){
                $(this).attr('src', 'img/choose-d.png')
            }else {
                $(this).attr('src', 'img/choose-g.png')
            }
        })
        $(this).find('img').attr('src', src)
        $('#third img').attr('src', src)

        currentSta = num;
    })
    $('#next').on('click', function () {
        if((currentPage > 2 ) || (currentPage === 1 && !currentSta) || (currentPage === 2 && !$('input[name="agree"]')[0].checked)){
            return
        }
        if(currentPage === 1){
            $('#first').addClass('hidden');
            $('.currentstate span').removeClass('currentState')
            $('.currentstate span').eq(1).addClass('currentState')
            $('#second').removeClass('hidden')
        }else if(currentPage === 2){
            if(currentSta === 1){
                $('#third p').eq(0).text('完成实名认证，审核过后就能拥有个人店铺了')
                $('#third a').text('去进行实名认证>>').attr('href', 'authentication.html?personal=true')
            }else {
                $('#third p').eq(0).text('完成企业认证，审核过后就能拥有企业店铺了')
                $('#third a').text('去进行企业认证>>').attr('href', 'authentication.html')
            }
            $('#second').addClass('hidden');
            $('.currentstate span').removeClass('currentState')
            $('.currentstate span').eq(2).addClass('currentState')
            $(this).hide()
            $('#third').removeClass('hidden')
        }
        currentPage ++;
    })
    $('#backPage').on('click', function () {
        $('#next').show();
        if(currentPage == 1){
            window.history.back();
        }else if(currentPage == 2){
            $('#first').removeClass('hidden');
            $('#second').addClass('hidden')
            $('.currentstate span').removeClass('currentState')
            $('.currentstate span').eq(0).addClass('currentState')
            $('#third').addClass('hidden')
        }else if(currentPage === 3){
            $('#first').addClass('hidden');
            $('#second').removeClass('hidden')
            $('.currentstate span').removeClass('currentState')
            $('.currentstate span').eq(1).addClass('currentState')
            $('#third').addClass('hidden')
        }
        currentPage--
    })
})